﻿$(document).ready(function () {
    $('.button.remove a').click(function () {

        if (confirm('Bạn có chắc không?')) {
            var files = '';
            $('#product-list input[type=checkbox]:checked').each(function () {
                files += $(this).closest('div').next().find('span').text() + ';';
            });

            var result = false;
            $.ajax({
                type: "POST",
                url: "/Admin/HomeUploaded.aspx/DeleteFiles",
                data: JSON.stringify({ files: files }),
                contentType: "application/json",
                async: false,
                success: function (data) {
                    result = data.d;
                },
                error: function () {
                    result = false;
                }
            });

            if (result) {
                location.reload();
            }
        }
    });

    $('.button.upload a').click(function () {
        setupUpload('#file-explorer', 'products');
        $("#dialog-upload").dialog("open");
    });
});

function acceptDialog() {
    var files = '';
    $('#file-explorer input[type=checkbox]:checked').each(function () {
        files += $(this).closest('div').next().prop('title') + ';';
    });

    var result = false;
    $.ajax({
        type: "POST",
        url: "/Admin/HomeUploaded.aspx/MoveFiles",
        data: JSON.stringify({ files: files }),
        contentType: "application/json",
        async: false,
        success: function (data) {
            result = data.d;
        },
        error: function () {
            result = false;
        }
    });

    if (result) {
        location.reload();
    }
}